import java.io.File;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		long start = System.currentTimeMillis();
		
		ComplexNormalizer normalizer = new ComplexNormalizer();
		normalizer.addNormalizer(new StopWordsNormalizer());
		//normalizer.addNormalizer(new StemNormalizer());
		
		int classes = Integer.parseInt(args[0]);
		DocumentsLoader loader = new DocumentsLoader(classes, normalizer);
		loader.loadTrainingDocuments(args[1]);
		TrainingResult result = Learner.train(loader);	
		
//		Map<String, double[]> condprob = result.condprob;
//		for(String key : condprob.keySet()) {
//			for (double p : condprob.get(key)) {
//				System.out.print(String.format("%.3f \t", p));
//			}
//			System.out.println(key);
//		}
		
		File[] files = (new File(args[2])).listFiles();
		StringBuilder answB = new StringBuilder();
		
		for(File f : files) {
			Document doc = DocumentsLoader.docFromFile(f, normalizer);
			int c = Learner.apply(loader.getClasses(), result, doc);
			answB.append(String.format("Document: %s Class: %d \n", f.getName(), c));
		}
		
		long stop = System.currentTimeMillis();
		
		System.out.println(answB.toString());
	}
}
